<?php


namespace app\Shop\controller;


use app\model\Shop;
use app\model\Shoplogin;

//商户注册//
class Register {
	function index(){
		$input = input('post.');
		if (empty($input['account']) || empty($input['password'])){
			return json(['status'=>false,'msg'=>'账号密码不能为空']);
		}
		try {
			$ct =Shoplogin::getByAccount($input['account']);
			if (!empty($ct)){
				throw new \Exception('用户已存在');
			}
			Shoplogin::Insert([
				'account'=>$input['account'],
				'password'=>$input['password']
			]);
			$data=Shoplogin::Where(['account'=>$input['account']])->select();
			Shop::insert([
				'name'=>$input['name'],
				'address'=>$input['address'],
				'type'=>$input['type'],
				'Shoplogin_id'=>$data['0']['id'],
				'phone'=>$input['phone'],
				'district'=>$input['district'],
			]);
			return ['status' =>true,];
		}catch (\Exception $e){
			return json(['status' =>false, 'error'=>$e->getMessage()]);
		}
	}
}